package lab02.test24;

import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        System.out.println("输入第一个日期，格式20100101");
        Calendar calendar=Calendar.getInstance();
        String s=scanner.nextLine();
        String year=s.substring(0,4);
        String month=s.substring(4,6);
        String day=s.substring(6);
        calendar.set(Integer.parseInt(year),Integer.parseInt(month),Integer.parseInt(day));
        Date date1=calendar.getTime();
        System.out.println("输入第二个日期，格式20100101");
        s=scanner.nextLine();
        year=s.substring(0,4);
        month=s.substring(4,6);
        day=s.substring(6);
        calendar.set(Integer.parseInt(year),Integer.parseInt(month),Integer.parseInt(day));
        Date date2=calendar.getTime();
        long subDay=(date1.getTime()-date2.getTime())/(24*60*60*1000);
        if(subDay<0){
            subDay=(date2.getTime()-date1.getTime())/(24*60*60*1000);
            System.out.println("两个日期相距"+subDay+"天");
        }
    }
}
